//
//  KBaseTableViewController.m
//  Peanut
//
//  Created by Jim huang on 2018/3/12.
//  Copyright © 2018年 Jim_Peanut. All rights reserved.
//

#import "KBaseTableViewController.h"

@interface KBaseTableViewController ()

@end

@implementation KBaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (@available(iOS 11.0,*)) {
        UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

#pragma mark - 懒加载
-(KBaseTableView *)tableView{
    if (!_tableView) {
        KBaseTableView* tableView = [[KBaseTableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectZero];
        tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
        tableView.separatorInset = UIEdgeInsetsZero;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.refreshProtocol = self;
        tableView.refreshEnable = YES;
        tableView.loadmoreEnable = YES;
        [self.view addSubview:tableView];
        _tableView = tableView;
        
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.view);
            make.top.equalTo(self.mas_topLayoutGuideBottom);
            make.bottom.equalTo(self.mas_bottomLayoutGuideTop);
        }];
    }
    return _tableView;
}

#pragma mark - UITableViewDelegate/UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return nil;
}


#pragma mark ----数据源---

-(NSInteger)page{
    if (!_page) {
        _page = 1;
    }
    return _page;
}
-(NSInteger)totalPage{
    if (!_totalPage) {
        _totalPage = 1;
    }
    return _totalPage;
}

-(NSInteger)pageSize{
    if (!_pageSize) {
        _pageSize = 10;
    }
    return _pageSize;
}
-(NSMutableArray *)data{
    if (!_data) {
        _data = [NSMutableArray array];
    }
    return _data;
}


#pragma mark - RefreshProtocol  //留给子类实现
-(void)refresh{
    self.page = 1;
    [self.data removeAllObjects];
}
-(void)loadmore{
    self.page ++;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
